home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-06-15 | 7.7 KB | 263 lines | [TEXT/PJMM] |
- { Generic FKEY Installer © 1990 by Jon Wind }
- { Version 1.0 on 6/15/90 }
-
-
- { This program is a generic FKEY installer shell, designed to install a single FKEY. The }
- { FKEY to be installed must be located in the installer's resource fork along with an }
- { "STR " #128 with the name of the FKEY to be installed. If the "STR " resource is }
- { missing, or does not match the name of the FKEY, the installer will not load. If the }
- { Installer is unable to install the FKEY, it will beep. }
-
-
- program FKEYinstaller;
-
-
- const
- DlgID = 128;
- StrID = 128;
- btn1 = 5;
- btn2 = 6;
- btn3 = 7;
- btn10 = 14;
- bCancel = 1;
- bInstall = 2;
- MaxBtnWidth = 135;
- SysResFile = 0;
- On = 1;
- Off = 0;
- Disable = 255;
-
- var
- myResFile: Integer;
- WatchCurs: CursHandle;
-
-
-
- procedure GetSetBtn (theDialog: DialogPtr; Btn, BtnState: Integer);
- { update button status for dialog }
- var
- theType: Integer;
- itmRect: Rect;
- itmHdl: Handle;
- begin
- GetDItem(theDialog, Btn, theType, itmHdl, itmRect); { get button junk }
- if BtnState <> Disable then
- begin
- HiliteControl(ControlHandle(itmHdl), Off); { enable control }
- SetCtlValue(ControlHandle(itmHdl), BtnState) { set button state }
- end
- else
- HiliteControl(ControlHandle(itmHdl), BtnState); { disable control }
- end; { of proc GetSetBtn }
-
-
- procedure RenameCtrl (theDialog: DialogPtr; ItemNumber: Integer; strvar: Str255);
- { rename a control }
- var
- curname: Str255;
- theType: Integer;
- btnHdl: Handle;
- btnRect: Rect;
- begin
- GetDItem(theDialog, ItemNumber, theType, btnHdl, btnRect);
- GetCTitle(ControlHandle(btnHdl), curname);
- if curname <> strvar then
- SetCTitle(ControlHandle(btnHdl), strvar);
- end; { of proc RenameCtrl }
-
-
- procedure DrawDefaultBtn (theDialog: DialogPtr; ItemNumber: Integer);
- { outline default button in dialog window }
- var
- theType: Integer;
- btnHdl: Handle;
- btnRect: Rect;
- begin
- SetPort(theDialog); { set window to current graf port }
- GetDItem(theDialog, DialogPeek(theDialog)^.aDefItem, theType, btnHdl, btnRect);
- Pensize(3, 3); { no wimpy button outlines here }
- InsetRect(btnRect, -4, -4); { set rectangle around button }
- FrameRoundRect(btnRect, 16, 16); { draw the sucker! }
- PenNormal;
- end; { of proc DrawDefaultBtn }
-
-
- procedure CenterAlert (theDialog: DialogPtr);
- { center dialog and hilight OK button }
- var
- itmrect: Rect;
- itemHdl: Handle;
- theType: Integer;
- itemRect: Rect;
- begin
- SetPort(theDialog); { set window to current graf port }
- with screenBits, theDialog^ do
- MoveWindow(theDialog, ((bounds.right - bounds.left - portrect.right + portrect.left) div 2), ((bounds.bottom - bounds.top - portrect.bottom + portrect.top + 20) div 3), True);
- GetDItem(theDialog, 3, theType, itemHdl, itemRect); { get item's rect }
- SetDItem(theDialog, 3, userItem + itemDisable, Handle(@DrawDefaultBtn), itemRect);
- end; { of proc CenterAlert }
-
-
- function aNum2Str (aNum: LongInt): Str255;
- { NumToString procedure available as a function }
- var
- NumStr: Str255;
- begin
- NumToString(aNum, NumStr);
- aNum2Str := NumStr;
- end; { of func aNum2Str }
-
- function GetFKEY (rezTitle: Str255; rezID, theRezFile: Integer): Handle;
- { return a Handle to the desired FKEY resource in the desired resource - returns nil if not found }
- { I would rather use CountResources and Get1IndResource, but I went for compatability instead }
- var
- aHndl: Handle;
- foundID, index, oldResFile: Integer;
- foundName: Str255;
- found: Boolean;
- theType: ResType;
- begin
- oldResFile := CurResFile;
- UseResfile(theRezFile);
- found := false;
- for index := 1 to CountResources('FKEY') do
- if not found then
- begin
- aHndl := GetIndResource('FKEY', index);
- if HomeResfile(aHndl) = theRezFile then
- begin
- GetResInfo(aHndl, foundID, theType, foundName); { get name of resource }
- if Length(rezTitle) > 0 then
- found := (foundName = rezTitle) { found correctly named resource }
- else
- found := (foundID = rezID); { found correctly numbered resource }
- end
- else { found a resource in the wrong file… }
- ReleaseResource(aHndl);
- end;
- UseResfile(oldResFile);
- if found then
- GetFKEY := aHndl
- else
- GetFKEY := nil;
- end; { of func GetFKEY }
-
-
- procedure DoIt;
- { do everything… }
- var
- i, theItem, theSlot: Integer;
- DlgPtr: DialogPtr;
- StrHdl: StringHandle;
- InstFKEYName, RezName: Str255;
- ItemHdl, InstFKEYHdl: Handle;
- theType: ResType;
- goNext: Boolean;
- theErr: OSErr;
- begin
- theSlot := 0;
- StrHdl := GetString(StrID);
- InstFKEYName := StrHdl^^;
- if StrHdl <> nil then
- begin
- InstFKEYHdl := GetFKEY(InstFKEYName, 0, myResFile);
- if InstFKEYHdl <> nil then
- begin
- DetachResource(InstFKEYHdl);
- HNoPurge(InstFKEYHdl);
- ParamText(InstFKEYName, '', '', '');
- DlgPtr := getNewDialog(DlgID, nil, Pointer(-1));
- CenterAlert(DlgPtr);
-
- for i := btn1 to btn2 do
- GetSetBtn(DlgPtr, i, Disable); { disable slots 1 & 2 }
-
- for i := btn3 to btn10 do
- begin
- if i < btn10 then
- theItem := Succ(i - btn1)
- else
- theItem := 0;
-
- ItemHdl := GetFKEY('', theItem, 0);
- if (ItemHdl <> nil) then { found in System File… }
- begin
- GetResInfo(ItemHdl, theItem, theType, RezName); { get name of resource }
- if Length(RezName) = 0 then
- RezName := '[No Name]';
- ReleaseResource(ItemHdl);
- RezName := Concat(aNum2Str(theItem), ' - ', RezName);
- if StringWidth(RezName) > MaxBtnWidth then { simple truncating algorithm }
- begin
- RezName := Concat(RezName, '…');
- while StringWidth(RezName) > MaxBtnWidth do
- Delete(RezName, Pred(Length(RezName)), 1);
- end;
- RenameCtrl(DlgPtr, i, RezName); { set button name }
- goNext := True;
- end;
- end;
-
- ShowWindow(DlgPtr);
- initCursor;
-
- repeat
- if theSlot = 0 then
- GetSetBtn(DlgPtr, bInstall, Disable)
- else
- GetSetBtn(DlgPtr, bInstall, Off);
- ModalDialog(nil, theItem);
- case theItem of
- bInstall:
- begin
- SetCursor(WatchCurs^^);
- UseResFile(SysResFile);
- theErr := noErr;
- theSlot := Succ(theSlot - btn1); { adjust installation slot flag to real FKEY slot number }
- ItemHdl := GetFKEY('', theSlot, 0);
- if (ItemHdl <> nil) then { found in System File… }
- begin
- RmveResource(ItemHdl);
- theErr := ResError;
- DisposHandle(ItemHdl);
- end;
-
- if theErr = noErr then
- begin
- AddResource(InstFKEYHdl, 'FKEY', theSlot, InstFKEYName);
- if ResError = noErr then
- WriteResource(InstFKEYHdl)
- else
- SysBeep(3);
- UpdateResFile(0);
- end
- else
- SysBeep(3);
-
- end;
- Btn1..Btn10:
- begin
- if theSlot > 0 then { slot flag is used here to save the selected button number }
- GetSetBtn(DlgPtr, theSlot, Off);
- theSlot := theItem;
- GetSetBtn(DlgPtr, theSlot, On);
- end;
- otherwise
- end;
- until (theItem = bCancel) or (theItem = bInstall);
- DisposDialog(DlgPtr);
- HPurge(InstFKEYHdl);
- ReleaseResource(InstFKEYHdl);
- end;
- end;
- end; { of proc Initialize }
-
-
- begin
- WatchCurs := GetCursor(watchcursor); { read in from system resource }
- MoveHHi(Handle(WatchCurs)); { to avoid fragging when it's locked }
- HLock(Handle(WatchCurs)); { lock the handle down }
- SetCursor(WatchCurs^^); { bring up watch cursor ASAP }
- myResFile := CurResFile;
- DoIt;
- end.